package com.hz.ws;

import com.hz.base.beans.vo.CommonResult;
import com.hz.base.beans.vo.Page;
import com.hz.base.beans.vo.PageEntity;
import com.hz.base.beans.vo.QueryParams;
import com.hz.beans.user.entity.TRecipient;
import com.hz.interfaces.user.inf.ITRecipientInterface;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.beetl.ext.fn.StringUtil;
import java.util.Map;

/**
 * @author mcz
 * @Date 2018/10/8 10:22
 * @Description 达者控制器
 * @Version 1.0
 */
@Api(tags = "达者管理",description = "CURD")
@Controller
@RequestMapping("/recipient")
@CrossOrigin
public class RecipientController {

    @Autowired
    private ITRecipientInterface itRecipientInterface;

    @ApiOperation(value="获取达者列表页面", notes="获取达者列表页面")
    @RequestMapping(value = "/getRecipientList" ,method = {RequestMethod.GET,RequestMethod.POST})
    public ModelAndView getRecipientList( TRecipient tRecipient, Page page){
        CommonResult<PageEntity> results=queryForPage(tRecipient,page);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("results",results);
        modelAndView.setViewName("page/recipientList");
        return modelAndView;
    }

    @RequestMapping(value = "/refreshAjax",method = {RequestMethod.GET,RequestMethod.POST})
    public String refreshAjax(TRecipient tRecipient, Page page,String refreshName, Map<String,Object> map){
        CommonResult<PageEntity> results=queryForPage(tRecipient,page);
        map.put("results",results);
        return "page/recipientList#"+refreshName;
    }
    /**
     * @Author mcz
     * @Description  分页
     * @Date 2018/10/15 11:17
     * @Param  TRecipient tRecipient, Page page
     * @return  CommonResult<PageEntity>
     **/
    private  CommonResult<PageEntity> queryForPage(TRecipient tRecipient, Page page){
        QueryParams<TRecipient> queryParams=new QueryParams<>();
        queryParams.setEntity(tRecipient);
        queryParams.setPaging(page);
        CommonResult<PageEntity> results=itRecipientInterface.queryForPage(queryParams);
        return  results;
    }










}
